package com.trendytech.tds.common.security;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.trendytech.tds.entity.Role;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
/*	@Autowired
	private IUserService userService;
	@Autowired
	private IRoleService roleService;*/

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
/*		com.trendytech.tds.entity.User user = userService.getByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException(username);
		}
		Collection<GrantedAuthority> grantedAuths = getGrantedAuthorities(user);

		User userdetail = new User(user.getUsername(), user.getPassword(),
				grantedAuths);*/
		return null;
	}

	// 取得用户的角色权限
	private Set<GrantedAuthority> getGrantedAuthorities(com.trendytech.tds.entity.User user) {
/*		Set<GrantedAuthority> authSet = new HashSet<GrantedAuthority>();
		List<Role> roles = roleService.getByUserId(user.getId());

		for (Role role : roles) {
			authSet.add(new SimpleGrantedAuthority(role.getName()));
		}
		return authSet;*/
		return null;
	}
}
